package com.ysxsoft.wdg.adapter;


import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.bean.response.CouponListResponse;
import com.ysxsoft.wdg.bean.response.MyRedPackBean;
import com.ysxsoft.wdg.ui.activity.center_st.StShopDetailActivity;

public class QuanAdapter extends BaseQuickAdapter<CouponListResponse.DataBean,BaseViewHolder> {

    private int type = 0;

    public void setType(int type){
        this.type = type;
        notifyDataSetChanged();
    }

    public QuanAdapter(int layoutResId) {
        super(layoutResId);
    }

    public void clear(){
        getData().clear();
        notifyDataSetChanged();
    }


    @Override
    protected void convert(BaseViewHolder helper,CouponListResponse.DataBean item) {
        int position = helper.getLayoutPosition();

        helper.setText(R.id.tv_money,item.getPrice());
        helper.setText(R.id.tv_shop,"仅限"+item.getCompany()+"店铺使用");
        helper.setText(R.id.tv_time,"有效时间至"+item.getEndtime());
        helper.setText(R.id.tv_m_j,"满"+item.getLimit()+"元减"+item.getPrice());
        
        TextView tv2Use = helper.getView(R.id.tv_2_use);
        TextView tvUsed = helper.getView(R.id.tv_used);

        LinearLayout llR = helper.getView(R.id.ll_quan_r);
        LinearLayout llL = helper.getView(R.id.ll_quan_l);

        if (type != 2) {
            if (type == 0) {//未使用
                tv2Use.setVisibility(View.VISIBLE);
                tvUsed.setVisibility(View.GONE);

                tv2Use.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        StShopDetailActivity.start(mContext,item.getCompanyid()+"");
                    }
                });

            } else if (type == 1) {//已使用
                tv2Use.setVisibility(View.GONE);
                tvUsed.setVisibility(View.VISIBLE);
                tvUsed.setText("已使用");
            }
            llL.setBackgroundResource(position%2==0?R.mipmap.quan_blue_l:R.mipmap.quan_red_l);
            llR.setBackgroundResource(position%2==0?R.mipmap.quan_blue_r:R.mipmap.quan_red_r);
        }else {//过期
            tv2Use.setVisibility(View.GONE);
            tvUsed.setVisibility(View.VISIBLE);
            tvUsed.setText("已过期");

            llL.setBackgroundResource(R.mipmap.quan_gray_l);
            llR.setBackgroundResource(R.mipmap.quan_gray_r);
        }
    }
}
